package UIFree.controls
{
	import UIFree.uif_component;
	import UIFree.uif_ecomponent;
	
	import flash.display.DisplayObject;
	import flash.geom.Rectangle;

	public class uif_maskedArea extends uif_ecomponent {
		private var _mask: uif_ecomponent;
		public function uif_maskedArea(parent:uif_component, ax:int=0, ay:int=0, awidth:int=0, aheight:int=0, styleClass: Object='') {
			super(parent, ax, ay, awidth, aheight, styleClass);
		}
		
		protected function maskCreate(): void {
			var rect: Rectangle = getInner();
			_mask = new uif_ecomponent(this, rect.x, rect.y, rect.width, rect.height, 'white');
			addChild(_mask);
		}
		
		override protected function updateBounds(): uif_component {
			if (!_mask) maskCreate();
			_mask.setRect(getInner());
			return super.updateBounds();
		}
		
		override public function addChild(child:DisplayObject): DisplayObject {
			if (child != _mask) child.mask = _mask;
			return super.addChild(child);
		}
		
		public function get maskBounds(): Rectangle {
			if (!_mask) maskCreate();
			return _mask.getBounds(this);
		}
	}
}